﻿jQuery.postJSON = function (url, data, success, type) {
    return jQuery.ajax({
        type: "POST",
        url: url,
        data: JSON.stringify(data),
        contentType: "application/json; charset=utf-8",
        dataType: typeof (type) == "undefined" ? 'json' : type,
        success: success,
        error: (jqXHR, textStatus, errorThrown) => {
            if (jqXHR.responseText.indexOf('NoLogin') > 1) {
                top.location.href = 'login.html';
            };
        }
    });
};

jQuery.getData = function (url, data, success, type) {
    if (arguments.length === 3) {
        return jQuery.ajax({
            type: "GET",
            url: url,
            data: data,
            dataType: typeof (type) == "undefined" ? 'json' : success,
            success: success,
            error: (jqXHR, textStatus, errorThrown) => {
                if (jqXHR.responseText.indexOf('NoLogin') > 1) {
                    top.location.href = 'login.html';
                };
            }
        });
    } else if (arguments.length === 2) {
        return jQuery.ajax({
            type: "GET",
            url: url,
            dataType: typeof (success) == "undefined" ? 'json' : success,
            success: data,
            error: (jqXHR, textStatus, errorThrown) => {
                if (jqXHR.responseText.indexOf('NoLogin') > 1) {
                    top.location.href = 'login.html';
                };
            }
        });
    } else if (arguments.length === 4) {
        return jQuery.ajax({
            type: "GET",
            url: url,
            data: data,
            dataType: type,
            success: success,
            error: (jqXHR, textStatus, errorThrown) => {
                if (jqXHR.responseText.indexOf('NoLogin') > 1) {
                    top.location.href = 'login.html';
                };
            }
        });
    }
};
//jQuery.getData = function (url, data, success, type) {
//    return jQuery.ajax({
//        type: "GET",
//        url: url,
//        data: data,
//        dataType: type,
//        success: success,
//        error: (jqXHR, textStatus, errorThrown) => {
//            if (jqXHR.responseText.indexOf('NoLogin') > 1) {
//                top.location.href = 'login.html';
//            };
//        }
//    });
//};
//jQuery.getData = function (url, success, type) {
//    return jQuery.ajax({
//        type: "GET",
//        url: url,
//        dataType: type,
//        success: success,
//        error: (jqXHR, textStatus, errorThrown) => {
//            if (jqXHR.responseText.indexOf('NoLogin') > 1) {
//                top.location.href = 'login.html';
//            };
//        }
//    });
//};

var API_RES_CODE = {
    SUCCESS: 200
}
